package com.project.andeper.paperproject;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.wyk.greendaodemo.greendao.gen.HourData;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.view.LineChartView;

public class ShowElectricForHourActivity extends AppCompatActivity {

    DBManager dbManager = new DBManager(this);
    @BindView(R.id.hour_title)
    TextView hourTitle;
    @BindView(R.id.hour_chart)
    LineChartView hourChart;
    @BindView(R.id.btn_cost)
    Button btnCost;

    List<Integer> integers;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Log.e("zzssxx","1");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_electric_for_hour);
        ButterKnife.bind(this);

        String value = getIntent().getStringExtra("number");
        integers = new ArrayList<>();
        //Log.e("zzssxx",value);
        List<HourData> hourDatas = dbManager.queryHourData(value);
        // Log.e("zzssxx","3");
        for (int i = 0; i < hourDatas.size(); i++) {
            integers.add((int) hourDatas.get(i).getConsumption());
        }
        List<PointValue> pointValues = new ArrayList<>();
        pointValues.add(new PointValue(0, integers.get(0)));
        pointValues.add(new PointValue(1, integers.get(1)));
        pointValues.add(new PointValue(2, integers.get(2)));
        pointValues.add(new PointValue(3, integers.get(3)));
        pointValues.add(new PointValue(4, integers.get(4)));
        pointValues.add(new PointValue(5, integers.get(5)));
        pointValues.add(new PointValue(6, integers.get(6)));
        pointValues.add(new PointValue(7, integers.get(7)));

        String[] x = {"一时", "二时", "三时", "四时", "五时", "六时", "七时", "八时"};
        Line line = new Line(pointValues).setColor(Color.BLUE).setCubic(true);
        line.setHasLabelsOnlyForSelected(true);
        List<Line> lines = new ArrayList<Line>();


        lines.add(line);

        LineChartData data = new LineChartData();

        data.setLines(lines);

        Axis axisX = new Axis(); //X轴
        axisX.setName("时刻");
        List<AxisValue> mAxisXValues = new ArrayList<AxisValue>();
        for (int i = 0; i < x.length; i++) {
            mAxisXValues.add(new AxisValue(i).setLabel(x[i]));
        }
        axisX.setValues(mAxisXValues);
        axisX.setTextColor(Color.BLACK);
        data.setAxisXBottom(axisX);


        Axis axisY = new Axis();  //Y轴
        axisY.setName("用电量");//y轴标注
        data.setAxisYLeft(axisY);  //Y轴设置在左边
        axisY.setTextColor(Color.BLACK);
        hourChart.setLineChartData(data);

    }
    
}
